package com.star.domain;


import com.alibaba.fastjson.JSON;
import lombok.*;

import javax.persistence.*;
import java.util.Map;
import java.util.Set;



/**
 * 页面配置信息
 *
 * @author 孙星阳
 * @date 2017/9/27 下午3:28
 */
@Table(name = "conf_page_info", uniqueConstraints = {@UniqueConstraint(columnNames = {"urlRgx"})})
@Entity
@Getter
@Setter
@ToString
@AllArgsConstructor
@NoArgsConstructor
public class PageInfo extends AbstractEntity {

    private static final long serialVersionUID = 1L;

    @Column(name = "pageUrl", nullable = false)
    private String pageUrl;

    @Column(name = "city", nullable = false)
    private String city;

    @Column(name = "site", nullable = false)
    private String site;

    @Column(name = "siteType", nullable = false)
    private String siteType;

    @Column(name = "urlRgx", columnDefinition = "varchar(1000)COMMENT 'URL正则表达式'", nullable = false)
    private String urlRgx;

    @Column(name = "method", columnDefinition = "varchar(10) default 'GET'", nullable = false)
    private String method;

    @Column(name = "paramsJson", columnDefinition = "text")
    private String paramsJson;


    public Map<String, Object> getParamsMap() {
        try {
            return JSON.parseObject(paramsJson, Map.class);
        } catch (Exception ex) {
            return null;
        }
    }

    @Column(name = "isJsRendering", columnDefinition = "char default '0' ", nullable = false)
    private String isJsRendering;

    @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
    @JoinColumn(name = "pageId", insertable = false, updatable = false)
    private Set<PageParseRegion> pageParseRegions;

    @Column(name = "pageValidationRule", columnDefinition = "varchar(500)")
    private String pageValidationRule;

}
